package com.polaris.live.ui.me.invite_reward

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.adapter.InvitePeopleAdapter
import com.polaris.live.common.mvvm.base2.BaseVbFragment
import com.polaris.live.databinding.FragmentMyInvitePeopleBinding
import com.polaris.live.translation.R
import com.polaris.live.utils.route.RoutePath
import com.polaris.live.utils.route.Router
import com.polaris.live.viewmodel.InviteFriendViewModel

/**
 * 我邀请的人
 *
 * @author Created by 半仙 on 2024/4/10/010 15:17
 */
class MyInvitePeopleFragment :
    BaseVbFragment<InviteFriendViewModel, FragmentMyInvitePeopleBinding>() {
    private val mAdapter by lazy { InvitePeopleAdapter() }
    override fun initView(savedInstanceState: Bundle?) {
        mBinding.peopleRecycler.apply {
            setEmptyTip(0, StringUtils.getString(R.string.no_inviters_yet))
            recycler.layoutManager = LinearLayoutManager(context)
            recycler.itemAnimator = null
            attachedAdapter(mAdapter, mViewModel).observe(
                this@MyInvitePeopleFragment,
                mViewModel.inviteBeListLiveData
            )
        }
        mViewModel.onRefresh()

        mAdapter.setOnItemClickListener { _, _, position ->
            val item = mAdapter.getItemOrNull(position) ?: return@setOnItemClickListener
            Router.builder(RoutePath.USER_SPACE_ACTIVITY)
                .withLong("userId", item.userBasic.userId)
                .withAny("userBasic", item.userBasic)
                .navigation(requireActivity())
        }
    }

}